package org.jeecg.modules.demo.hydrology.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.demo.hydrology.dto.AnalysisListDto;
import org.jeecg.modules.demo.hydrology.dto.CategoryDto;
import org.jeecg.modules.demo.hydrology.dto.AnalysisListDto;
import org.jeecg.modules.demo.hydrology.dto.LargeDto;
import org.jeecg.modules.demo.hydrology.entity.*;
import org.jeecg.modules.demo.hydrology.mapper.*;
import org.jeecg.modules.demo.hydrology.service.IAnalysisService;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.mapper.SysDepartMapper;
import org.jeecg.modules.system.service.ISysDepartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.WeekFields;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

/**
 * @author zhouwenhao
 * @date 2024/5/15
 * @dec 描述
 */
@Service
public class AnalysisServiceImpl implements IAnalysisService {

    @Autowired
    private LargeServiceImpl largeService;
    @Autowired
    private ISysDepartService sysDepartService;
    @Autowired
    private SysDepartMapper sysDepartMapper;
    @Autowired
    private CgkcdssMapper cgkcdssMapper;
    @Autowired
    private CgkcddyMapper cgkcddyMapper;
    @Autowired
    private CgkcdycMapper cgkcdycMapper;
    @Autowired
    private CgkyjMapper cgkyjMapper;
    @Autowired
    private CscdssMapper cscdssMapper;
    @Autowired
    private CscddyMapper cscddyMapper;
    @Autowired
    private CsyjMapper csyjMapper;
    @Autowired
    private DbcxcdssMapper dbcxcdssMapper;
    @Autowired
    private DbcxyjMapper dbcxyjMapper;
    @Autowired
    private DbcxcddyMapper dbcxcddyMapper;
    @Autowired
    private DbscdssMapper dbscdssMapper;
    @Autowired
    private DbscddyMapper dbscddyMapper;
    @Autowired
    private DbsyjMapper dbsyjMapper;
    @Autowired
    private PslcdssMapper pslcdssMapper;
    @Autowired
    private PslcddyMapper pslcddyMapper;
    @Autowired
    private PslcdycMapper pslcdycMapper;
    @Autowired
    private PslyjMapper pslyjMapper;
    @Autowired
    private WzcdssMapper wzcdssMapper;
    @Autowired
    private WzyjMapper wzyjMapper;
    @Autowired
    private WzcddyMapper wzcddyMapper;
    @Autowired
    private JslcdssMapper jslcdssMapper;
    @Autowired
    private JslcddyMapper jslcddyMapper;
    @Autowired
    private JslyjMapper jslyjMapper;
    @Autowired
    private YslcdssMapper yslcdssMapper;
    @Autowired
    private YslcddyMapper yslcddyMapper;
    @Autowired
    private YslyjMapper yslyjMapper;
    @Override
    public Analysis getTop(String paramsTime) {
        String timeStart=null;
        String timeEnd=null;
        switch (paramsTime){
            case "today":
                LocalDate today = LocalDate.now();
                DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                LocalDateTime startOfDay = today.atStartOfDay(); // 当天的开始时间
                LocalDateTime endOfDay = today.plusDays(1).atStartOfDay().minusSeconds(1);
                timeStart=startOfDay.format(fmt);
                timeEnd=endOfDay.format(fmt);
                break;
            case "week":
                LocalDate week = LocalDate.now();
                DateTimeFormatter fmtWeek = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                DayOfWeek firstDayOfWeek = WeekFields.of(Locale.getDefault()).getFirstDayOfWeek();
                LocalDate startOfWeek = week.with(TemporalAdjusters.previousOrSame(firstDayOfWeek));
                LocalDate endOfWeek = startOfWeek.plusDays(6); // 假设一周有7天
                timeStart=startOfWeek.format(fmtWeek);
                timeEnd=endOfWeek.format(fmtWeek);
                break;
            case "month":
                LocalDate month = LocalDate.now();
                DateTimeFormatter fmtMonth = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                YearMonth currentYearMonth = YearMonth.from(month);
                LocalDate firstDayOfMonth = currentYearMonth.atDay(1);
                LocalDate lastDayOfMonth = currentYearMonth.lengthOfMonth() == 28
                        ? currentYearMonth.atDay(28)
                        : (currentYearMonth.isLeapYear() && currentYearMonth.getMonthValue() == 2)
                        ? currentYearMonth.atDay(29)
                        : currentYearMonth.atEndOfMonth();
                timeStart=firstDayOfMonth.format(fmtMonth);
                timeEnd=lastDayOfMonth.format(fmtMonth);
                break;
            case "year":
                LocalDate year = LocalDate.now();
                int currentYear = year.getYear();
                DateTimeFormatter fmtYear = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                LocalDate firstDayOfYear = LocalDate.of(currentYear, 1, 1);
                LocalDate lastDayOfYear = LocalDate.of(currentYear, 12, 31);
                timeStart=firstDayOfYear.format(fmtYear);
                timeEnd=lastDayOfYear.format(fmtYear);
                break;
            default:
                timeStart="1900-01-01";
                timeEnd="2100-12-31";
                break;
        }
        //长观孔
        QueryWrapper<Cgkcdss> queryWrapperCgkcdss = new QueryWrapper<>();
        queryWrapperCgkcdss.between("monitor_time",timeStart,timeEnd);
        Long monitoringRecordsCgkcdss =cgkcdssMapper.selectCount(queryWrapperCgkcdss);
        QueryWrapper<Cgkyj> queryWrapperCgkyj = new QueryWrapper<>();
        queryWrapperCgkyj.between("alarm_time",timeStart,timeEnd);
        Long warningsNumberCgk=cgkyjMapper.selectCount(queryWrapperCgkyj);
//        QueryWrapper<Cgkcddy> queryWrapperCgkcddy = new QueryWrapper<>();
//        Long devicesNumberCgk=cgkcddyMapper.selectCount(queryWrapperCgkcddy);
        Long devicesNumberCgk=cgkcddyMapper.selectDevicesNumber();
        QueryWrapper<Cgkcdyc> queryWrapperCgkcdyc = new QueryWrapper<>();
        queryWrapperCgkcdyc.between("data_time",timeStart,timeEnd);
        Long abnormalNumberCgk=cgkcdycMapper.selectCount(queryWrapperCgkcdyc);
        queryWrapperCgkyj.eq("alarm_status",'4');
        Long monitoringRateCgk=cgkyjMapper.selectCount(queryWrapperCgkyj);
        //抽放水
        QueryWrapper<Cscdss> queryWrapperCscdss = new QueryWrapper<>();
        queryWrapperCscdss.between("data_time",timeStart,timeEnd);
        Long monitoringRecordsCscdss =cscdssMapper.selectCount(queryWrapperCscdss);
        QueryWrapper<Csyj> queryWrapperCsyj = new QueryWrapper<>();
        queryWrapperCsyj.between("alarm_time",timeStart,timeEnd);
        Long warningsNumberCs=csyjMapper.selectCount(queryWrapperCsyj);
        Long devicesNumberCs=cscddyMapper.selectDevicesNumber();
        Long abnormalNumberCs=csyjMapper.selectCount(queryWrapperCsyj);
        queryWrapperCsyj.eq("alarm_status",'4');
        Long monitoringRateCs=csyjMapper.selectCount(queryWrapperCsyj);
        //地表沉陷
        QueryWrapper<Dbcxcdss> queryWrapperDbcxcdss = new QueryWrapper<>();
        queryWrapperDbcxcdss.between("data_time",timeStart,timeEnd);
        Long monitoringRecordsDbcxcdss =dbcxcdssMapper.selectCount(queryWrapperDbcxcdss);
        QueryWrapper<Dbcxyj> queryWrapperDbcxyj = new QueryWrapper<>();
        queryWrapperDbcxyj.between("alarm_time",timeStart,timeEnd);
        Long warningsNumberDbcx=dbcxyjMapper.selectCount(queryWrapperDbcxyj);
        QueryWrapper<Dbcxcddy> queryWrapperDbcxcddy = new QueryWrapper<>();
        Long devicesNumberDbcx=dbcxcddyMapper.selectDevicesNumber();
        Long abnormalNumberDbcx=dbcxyjMapper.selectCount(queryWrapperDbcxyj);
        queryWrapperDbcxyj.eq("alarm_status",'4');
        Long monitoringRateDbcx=dbcxyjMapper.selectCount(queryWrapperDbcxyj);
        //地表水
        QueryWrapper<Dbscdss> queryWrapperDbscdss = new QueryWrapper<>();
        queryWrapperDbscdss.between("monitor_time",timeStart,timeEnd);
        Long monitoringRecordsDbscdss =dbscdssMapper.selectCount(queryWrapperDbscdss);
        QueryWrapper<Dbsyj> queryWrapperDbsyj = new QueryWrapper<>();
        queryWrapperDbsyj.between("alarm_time",timeStart,timeEnd);
        Long warningsNumberDbs=dbsyjMapper.selectCount(queryWrapperDbsyj);
        QueryWrapper<Dbscddy> queryWrapperDbscddy = new QueryWrapper<>();
        Long devicesNumberDbs=dbscddyMapper.selectDevicesNumber();
        Long abnormalNumberDbs=dbsyjMapper.selectCount(queryWrapperDbsyj);
        queryWrapperDbsyj.eq("alarm_status",'4');
        Long monitoringRateDbs=dbsyjMapper.selectCount(queryWrapperDbsyj);
        //降水量
        QueryWrapper<Jslcdss> queryWrapperJslcdss = new QueryWrapper<>();
        queryWrapperJslcdss.between("monitor_time",timeStart,timeEnd);
        Long monitoringRecordsJslcdss =jslcdssMapper.selectCount(queryWrapperJslcdss);
        QueryWrapper<Jslyj> queryWrapperJslyj = new QueryWrapper<>();
        queryWrapperJslyj.between("alarm_time",timeStart,timeEnd);
        Long warningsNumberJsl=jslyjMapper.selectCount(queryWrapperJslyj);
        QueryWrapper<Jslcddy> queryWrapperJslcddy = new QueryWrapper<>();
        Long devicesNumberJsl=jslcddyMapper.selectDevicesNumber();
        Long abnormalNumberJsl=jslyjMapper.selectCount(queryWrapperJslyj);
        queryWrapperJslyj.eq("alarm_status",'4');
        Long monitoringRateJsl=jslyjMapper.selectCount(queryWrapperJslyj);
        //排水量
        QueryWrapper<Pslcdss> queryWrapperPslcdss = new QueryWrapper<>();
        queryWrapperPslcdss.between("monitor_time",timeStart,timeEnd);
        Long monitoringRecordsPslcdss =pslcdssMapper.selectCount(queryWrapperPslcdss);
        QueryWrapper<Pslyj> queryWrapperPslyj = new QueryWrapper<>();
        queryWrapperPslyj.between("alarm_time",timeStart,timeEnd);
        Long warningsNumberPsl=pslyjMapper.selectCount(queryWrapperPslyj);
        QueryWrapper<Pslcddy> queryWrapperPslcddy = new QueryWrapper<>();
        Long devicesNumberPsl=pslcddyMapper.selectDevicesNumber();
        QueryWrapper<Pslcdyc> queryWrapperPslcdyc = new QueryWrapper<>();
        queryWrapperPslcdyc.between("data_time",timeStart,timeEnd);
        Long abnormalNumberPsl=pslcdycMapper.selectCount(queryWrapperPslcdyc);
        queryWrapperPslyj.eq("alarm_status",'4');
        Long monitoringRatePsl=pslyjMapper.selectCount(queryWrapperPslyj);
        //微震
        QueryWrapper<Wzcdss> queryWrapperWzcdss = new QueryWrapper<>();
        queryWrapperWzcdss.between("occurred_time",timeStart,timeEnd);
        Long monitoringRecordsWzcdss =wzcdssMapper.selectCount(queryWrapperWzcdss);
        QueryWrapper<Wzyj> queryWrapperWzyj = new QueryWrapper<>();
        queryWrapperWzyj.between("alarm_time",timeStart,timeEnd);
        Long warningsNumberWz=wzyjMapper.selectCount(queryWrapperWzyj);
        QueryWrapper<Wzcddy> queryWrapperWzcddy = new QueryWrapper<>();
        Long devicesNumberWz=wzcddyMapper.selectDevicesNumber();
        Long abnormalNumberWz=wzyjMapper.selectCount(queryWrapperWzyj);
        queryWrapperWzyj.eq("alarm_status",'4');
        Long monitoringRateWz=wzyjMapper.selectCount(queryWrapperWzyj);
        //涌水量
        QueryWrapper<Yslcdss> queryWrapperYslcdss = new QueryWrapper<>();
        queryWrapperYslcdss.between("monitor_time",timeStart,timeEnd);
        Long monitoringRecordsYslcdss =yslcdssMapper.selectCount(queryWrapperYslcdss);
        QueryWrapper<Yslyj> queryWrapperYslyj = new QueryWrapper<>();
        queryWrapperYslyj.between("alarm_time",timeStart,timeEnd);
        Long warningsNumberYsl=yslyjMapper.selectCount(queryWrapperYslyj);
        QueryWrapper<Yslcddy> queryWrapperYslcddy = new QueryWrapper<>();
        Long devicesNumberYsl=yslcddyMapper.selectDevicesNumber();
        Long abnormalNumberYsl=yslyjMapper.selectCount(queryWrapperYslyj);
        queryWrapperYslyj.eq("alarm_status",'4');
        Long monitoringRateYsl=yslyjMapper.selectCount(queryWrapperYslyj);

        Analysis analysis=new Analysis();
        //监测记录
        String monitoringRecords=String.valueOf(monitoringRecordsCgkcdss+monitoringRecordsCscdss+monitoringRecordsDbcxcdss+monitoringRecordsDbscdss
        +monitoringRecordsJslcdss+monitoringRecordsPslcdss+monitoringRecordsWzcdss+monitoringRecordsYslcdss);
        analysis.setMonitoringRecords(monitoringRecords);
        //异常处理数
        String monitoringRate=String.valueOf(monitoringRateJsl+monitoringRateCgk+monitoringRateWz+monitoringRateDbcx+monitoringRateCs+monitoringRateDbs
        +monitoringRateYsl+monitoringRatePsl);
        analysis.setMonitoringRate(monitoringRate);
        //设备数
        String devicesNumber=String.valueOf(devicesNumberJsl+devicesNumberCgk+devicesNumberWz+devicesNumberDbcx+devicesNumberCs+devicesNumberDbs
        +devicesNumberYsl+devicesNumberPsl);
        analysis.setDevicesNumber(devicesNumber);
        //预警数
        String warningsNumber=String.valueOf(warningsNumberJsl+warningsNumberCgk+warningsNumberWz+warningsNumberDbcx+warningsNumberCs+warningsNumberDbs
        +warningsNumberYsl+warningsNumberPsl);
        analysis.setWarningsNumber(warningsNumber);
        //异常数
        String abnormalNumber=String.valueOf(abnormalNumberJsl+abnormalNumberCgk+abnormalNumberWz+abnormalNumberDbcx+abnormalNumberCs+abnormalNumberDbs
        +abnormalNumberYsl+abnormalNumberPsl);
        analysis.setAbnormalNumber(abnormalNumber);
        return analysis;
    }

    @Override
    public List<String> getBottomLeft() {
        List<CategoryDto> list= largeService.getCategory();
        List<String> categoryList = list.stream()
                .map(categoryDto -> {
                    return  categoryDto.getCategoryCount();
                })
                .collect(Collectors.toList());
        return categoryList;
    }

    @Override
    public List<String> getBottomRightTopLeft() {
        LargeDto list= largeService.getTotalAlarm();
        int num=Integer.parseInt(list.getAlarmLevel1())+Integer.parseInt(list.getAlarmLevel2())+
                Integer.parseInt(list.getAlarmLevel3())+Integer.parseInt(list.getAlarmLevel4());
        List<String> total=new ArrayList<>();
        total.add(String.valueOf((Double.parseDouble(list.getAlarmLevel1())*100/num)));
        total.add(String.valueOf((Double.parseDouble(list.getAlarmLevel2())*100/num)));
        total.add(String.valueOf((Double.parseDouble(list.getAlarmLevel3())*100/num)));
        total.add(String.valueOf((Double.parseDouble(list.getAlarmLevel4())*100/num)));
        return total;
    }

    @Override
    public List<AnalysisListDto> getAnalysisList(String code) {
        List<AnalysisListDto> analysisListDtoArrayList=new ArrayList<>();
        analysisListDtoArrayList=switchAll(code);
        return analysisListDtoArrayList;
    }

    /**
     * 实时通知排水量
     * @return
     */
    List<AnalysisListDto> switchPslcdss(String codestationMine){
        List<AnalysisListDto> AnalysisListDtoList=new ArrayList<>();
        // 获取当前时间
        LocalDate today = LocalDate.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startOfDay = today.atStartOfDay(); // 当天的开始时间
        LocalDateTime endOfDay = today.plusDays(1).atStartOfDay().minusSeconds(1);
        String timeStart = startOfDay.format(fmt);
        String timeEnd = endOfDay.format(fmt);
        String str="140421005184";
        switch (codestationMine){
            case "0":
                str="all";
                break;
            case "140421005184":
                str="140421005184";
                break;
            case "140421005108":
                str="140421005108";
                break;
        }
        QueryWrapper<Pslcdss> queryWrapperPslcdss = new QueryWrapper<>();
        if ("all".equals(str)) {
        }else {
            queryWrapperPslcdss.eq("station_mine", str);
        }
        queryWrapperPslcdss.between("monitor_time",timeStart,timeEnd);
        List<Pslcdss> pslcdssList=pslcdssMapper.selectList(queryWrapperPslcdss);
        AtomicInteger atomicNum= new AtomicInteger(1);
        pslcdssList.stream().map(pslcdss -> {
            AnalysisListDto AnalysisListDto=new AnalysisListDto();
            AnalysisListDto.setMonitorType("排水量");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            AnalysisListDto.setMonitorTime(sdf.format(pslcdss.getMonitorTime()));
            AnalysisListDto.setMonitorValue(pslcdss.getValue().toString());
            QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
            sysDepartQueryWrapper.eq("org_code", pslcdss.getStationMine());
            SysDepart sysDepart = sysDepartMapper.selectOne(sysDepartQueryWrapper);
            AnalysisListDto.setStationName(sysDepart.getDepartName());
            AnalysisListDto.setMonitorStation(pslcdss.getLocation());
            AnalysisListDtoList.add(AnalysisListDto);
            return null;
        }).collect(Collectors.toList());
        return AnalysisListDtoList;
    }
    /**
     * 实时通知疏放水
     * @return
     */
    List<AnalysisListDto> switchCscdss(String codestationMine){
        List<AnalysisListDto> AnalysisListDtoList=new ArrayList<>();
        // 获取当前时间
        LocalDate today = LocalDate.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startOfDay = today.atStartOfDay(); // 当天的开始时间
        LocalDateTime endOfDay = today.plusDays(1).atStartOfDay().minusSeconds(1);
        String timeStart = startOfDay.format(fmt);
        String timeEnd = endOfDay.format(fmt);
        QueryWrapper<Cscdss> queryWrapperCscdss = new QueryWrapper<>();
        String str="140421005184";
        switch (codestationMine){
            case "0":
                str="all";
                break;
            case "140421005184":
                str="140421005184";
                break;
            case "140421005108":
                str="140421005108";
                break;
        }
        if ("all".equals(str)) {
        }else {
            queryWrapperCscdss.eq("station_mine", str);
        }
        queryWrapperCscdss.between("data_time",timeStart,timeEnd);
        List<Cscdss> cscdssList=cscdssMapper.selectList(queryWrapperCscdss);
        AtomicInteger atomicNumCscdss= new AtomicInteger(1);
        cscdssList.stream().map(cscdss -> {
            AnalysisListDto AnalysisListDto=new AnalysisListDto();
            AnalysisListDto.setMonitorType("疏放水");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            AnalysisListDto.setMonitorTime(sdf.format(cscdss.getDataTime()));
            AnalysisListDto.setMonitorValue(cscdss.getTotaFlow());
            QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
            sysDepartQueryWrapper.eq("org_code", cscdss.getStationMine());
            SysDepart sysDepart = sysDepartMapper.selectOne(sysDepartQueryWrapper);
            AnalysisListDto.setStationName(sysDepart.getDepartName());
            AnalysisListDto.setMonitorStation(cscdss.getEquipmentPosition());
            AnalysisListDtoList.add(AnalysisListDto);
            return null;
        }).collect(Collectors.toList());
        return AnalysisListDtoList;
    }
    /**
     * 实时通知长观孔
     * @return
     */
    List<AnalysisListDto> switchCgkcdss(String codestationMine){
        List<AnalysisListDto> AnalysisListDtoList=new ArrayList<>();
        // 获取当前时间
        LocalDate today = LocalDate.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startOfDay = today.atStartOfDay(); // 当天的开始时间
        LocalDateTime endOfDay = today.plusDays(1).atStartOfDay().minusSeconds(1);
        String timeStart = startOfDay.format(fmt);
        String timeEnd = endOfDay.format(fmt);
        QueryWrapper<Cgkcdss> queryWrapperCgkcdss = new QueryWrapper<>();
        String str="140421005184";
        switch (codestationMine){
            case "0":
                str="all";
                break;
            case "140421005184":
                str="140421005184";
                break;
            case "140421005108":
                str="140421005108";
                break;
        }
        if ("all".equals(str)) {
        }else {
            queryWrapperCgkcdss.eq("org_code", str);
        }
        queryWrapperCgkcdss.between("monitor_time",timeStart,timeEnd);
        List<Cgkcdss> cgkcdssList=cgkcdssMapper.selectList(queryWrapperCgkcdss);
        AtomicInteger atomicNumCgkcdss= new AtomicInteger(1);
        cgkcdssList.stream().map(cgkcdss -> {
            AnalysisListDto AnalysisListDto=new AnalysisListDto();
            AnalysisListDto.setMonitorType("长观孔");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            AnalysisListDto.setMonitorTime(sdf.format(cgkcdss.getMonitorTime()));
            AnalysisListDto.setMonitorValue(cgkcdss.getWaterLevel().toString());
            QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
            sysDepartQueryWrapper.eq("org_code", cgkcdss.getOrgCode());
            SysDepart sysDepart = sysDepartMapper.selectOne(sysDepartQueryWrapper);
            AnalysisListDto.setStationName(sysDepart.getDepartName());
            AnalysisListDto.setMonitorStation(cgkcdss.getLocation());
            AnalysisListDtoList.add(AnalysisListDto);
            return null;
        }).collect(Collectors.toList());
        return AnalysisListDtoList;
    }
    /**
     * 实时通知微震
     * @return
     */
    List<AnalysisListDto> switchWzcdss(String codestationMine){
        List<AnalysisListDto> AnalysisListDtoList=new ArrayList<>();
        // 获取当前时间
        LocalDate today = LocalDate.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startOfDay = today.atStartOfDay(); // 当天的开始时间
        LocalDateTime endOfDay = today.plusDays(1).atStartOfDay().minusSeconds(1);
        String timeStart = startOfDay.format(fmt);
        String timeEnd = endOfDay.format(fmt);
        QueryWrapper<Wzcdss> queryWrapperWzcdss = new QueryWrapper<>();
        String str="140421005184";
        switch (codestationMine){
            case "0":
                str="all";
                break;
            case "140421005184":
                str="140421005184";
                break;
            case "140421005108":
                str="140421005108";
                break;
        }
        if ("all".equals(str)) {
        }else {
            queryWrapperWzcdss.eq("station_mine", str);
        }
        queryWrapperWzcdss.between("occurred_time",timeStart,timeEnd);
        List<Wzcdss> wzcdssList=wzcdssMapper.selectList(queryWrapperWzcdss);
        AtomicInteger atomicNumWzcdss= new AtomicInteger(1);
        wzcdssList.stream().map(wzcdss -> {
            AnalysisListDto AnalysisListDto=new AnalysisListDto();
            AnalysisListDto.setMonitorType("微震");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            AnalysisListDto.setMonitorTime(sdf.format(wzcdss.getOccurredTime()));
            AnalysisListDto.setMonitorValue(wzcdss.getMagnitude().toString());
            QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
            sysDepartQueryWrapper.eq("org_code", wzcdss.getStationMine());
            SysDepart sysDepart = sysDepartMapper.selectOne(sysDepartQueryWrapper);
            AnalysisListDto.setStationName(sysDepart.getDepartName());
            AnalysisListDto.setMonitorStation(wzcdss.getMicroseismicStratum());
            AnalysisListDtoList.add(AnalysisListDto);
            return null;
        }).collect(Collectors.toList());
        return AnalysisListDtoList;
    }
    /**
     * 实时通知降水量
     * @return
     */
    List<AnalysisListDto> switchJsldss(String codestationMine){
        List<AnalysisListDto> AnalysisListDtoList=new ArrayList<>();
        // 获取当前时间
        LocalDate today = LocalDate.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startOfDay = today.atStartOfDay(); // 当天的开始时间
        LocalDateTime endOfDay = today.plusDays(1).atStartOfDay().minusSeconds(1);
        String timeStart = startOfDay.format(fmt);
        String timeEnd = endOfDay.format(fmt);
        QueryWrapper<Jslcdss> queryWrapperJslcdss = new QueryWrapper<>();
        String str="140421005184";
        switch (codestationMine){
            case "0":
                str="all";
                break;
            case "140421005184":
                str="140421005184";
                break;
            case "140421005108":
                str="140421005108";
                break;
        }
        if ("all".equals(str)) {
        }else {
            queryWrapperJslcdss.eq("station_mine", str);
        }
        queryWrapperJslcdss.between("monitor_time",timeStart,timeEnd);
        List<Jslcdss> jslcdssList=jslcdssMapper.selectList(queryWrapperJslcdss);
        AtomicInteger atomicNumJslcdss= new AtomicInteger(1);
        jslcdssList.stream().map(jslcdss -> {
            AnalysisListDto AnalysisListDto=new AnalysisListDto();
            AnalysisListDto.setMonitorType("降水量");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            AnalysisListDto.setMonitorTime(sdf.format(jslcdss.getMonitorTime()));
            AnalysisListDto.setMonitorValue(jslcdss.getValue().toString());
            QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
            sysDepartQueryWrapper.eq("org_code", jslcdss.getStationMine());
            SysDepart sysDepart = sysDepartMapper.selectOne(sysDepartQueryWrapper);
            AnalysisListDto.setStationName(sysDepart.getDepartName());
            AnalysisListDto.setMonitorStation(jslcdss.getEquipmentPosition());
            AnalysisListDtoList.add(AnalysisListDto);
            return null;
        }).collect(Collectors.toList());
        return AnalysisListDtoList;
    }
    /**
     * 实时通知地表岩移
     * @return
     */
    List<AnalysisListDto> switchDbcx(String codestationMine){
        List<AnalysisListDto> AnalysisListDtoList=new ArrayList<>();
        // 获取当前时间
        LocalDate today = LocalDate.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startOfDay = today.atStartOfDay(); // 当天的开始时间
        LocalDateTime endOfDay = today.plusDays(1).atStartOfDay().minusSeconds(1);
        String timeStart = startOfDay.format(fmt);
        String timeEnd = endOfDay.format(fmt);
        QueryWrapper<Dbcxcdss> queryWrapperDbcxcdss = new QueryWrapper<>();
        String str="140421005184";
        switch (codestationMine){
            case "0":
                str="all";
                break;
            case "140421005184":
                str="140421005184";
                break;
            case "140421005108":
                str="140421005108";
                break;
        }
        if ("all".equals(str)) {
        }else {
            queryWrapperDbcxcdss.eq("station_mine", str);
        }
        queryWrapperDbcxcdss.between("data_time",timeStart,timeEnd);
        List<Dbcxcdss> dbcxcdssList=dbcxcdssMapper.selectList(queryWrapperDbcxcdss);
        AtomicInteger atomicNumDbcxcdss= new AtomicInteger(1);
        dbcxcdssList.stream().map(dbcxcdss -> {
            AnalysisListDto AnalysisListDto=new AnalysisListDto();
            AnalysisListDto.setMonitorType("地表岩移");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            AnalysisListDto.setMonitorTime(sdf.format(dbcxcdss.getDataTime()));
            AnalysisListDto.setMonitorValue(dbcxcdss.getMiningDepth());
            QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
            sysDepartQueryWrapper.eq("org_code", dbcxcdss.getStationMine());
            SysDepart sysDepart = sysDepartMapper.selectOne(sysDepartQueryWrapper);
            AnalysisListDto.setStationName(sysDepart.getDepartName());
            AnalysisListDto.setMonitorStation(dbcxcdss.getRegionName());
            AnalysisListDtoList.add(AnalysisListDto);
            return null;
        }).collect(Collectors.toList());
        return AnalysisListDtoList;
    }
    /**
     * 实时通知地表水
     * @return
     */
    List<AnalysisListDto> switchDbscdss(String codestationMine){
        List<AnalysisListDto> AnalysisListDtoList=new ArrayList<>();
        // 获取当前时间
        LocalDate today = LocalDate.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startOfDay = today.atStartOfDay(); // 当天的开始时间
        LocalDateTime endOfDay = today.plusDays(1).atStartOfDay().minusSeconds(1);
        String timeStart = startOfDay.format(fmt);
        String timeEnd = endOfDay.format(fmt);
        QueryWrapper<Dbscdss> queryWrapperDbscdss = new QueryWrapper<>();
        String str="140421005184";
        switch (codestationMine){
            case "0":
                str="all";
                break;
            case "140421005184":
                str="140421005184";
                break;
            case "140421005108":
                str="140421005108";
                break;
        }
        if ("all".equals(str)) {
        }else {
            queryWrapperDbscdss.eq("station_mine", str);
        }
        queryWrapperDbscdss.between("monitor_time",timeStart,timeEnd);
        List<Dbscdss> dbscdssList=dbscdssMapper.selectList(queryWrapperDbscdss);
        AtomicInteger atomicNumDbscdss= new AtomicInteger(1);
        dbscdssList.stream().map(dbscdss -> {
            AnalysisListDto AnalysisListDto=new AnalysisListDto();
            AnalysisListDto.setMonitorType("地表水");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            AnalysisListDto.setMonitorTime(sdf.format(dbscdss.getMonitorTime()));
            AnalysisListDto.setMonitorValue(dbscdss.getValue().toString());
            QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
            sysDepartQueryWrapper.eq("org_code", dbscdss.getStationMine());
            SysDepart sysDepart = sysDepartMapper.selectOne(sysDepartQueryWrapper);
            AnalysisListDto.setStationName(sysDepart.getDepartName());
            AnalysisListDto.setMonitorStation("地表");
            AnalysisListDtoList.add(AnalysisListDto);
            return null;
        }).collect(Collectors.toList());
        return AnalysisListDtoList;
    }
    /**
     * 实时通知涌水量
     * @return
     */
    List<AnalysisListDto> switchYslcdss(String codestationMine){
        List<AnalysisListDto> AnalysisListDtoList=new ArrayList<>();
        // 获取当前时间
        LocalDate today = LocalDate.now();
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startOfDay = today.atStartOfDay(); // 当天的开始时间
        LocalDateTime endOfDay = today.plusDays(1).atStartOfDay().minusSeconds(1);
        String timeStart = startOfDay.format(fmt);
        String timeEnd = endOfDay.format(fmt);
        QueryWrapper<Yslcdss> queryWrapperYslcdss = new QueryWrapper<>();
        String str="140421005184";
        switch (codestationMine){
            case "0":
                str="all";
                break;
            case "140421005184":
                str="140421005184";
                break;
            case "140421005108":
                str="140421005108";
                break;
        }
        if ("all".equals(str)) {
        }else {
            queryWrapperYslcdss.eq("station_mine", str);
        }
        queryWrapperYslcdss.between("monitor_time",timeStart,timeEnd);
        List<Yslcdss> yslcdssList=yslcdssMapper.selectList(queryWrapperYslcdss);
        AtomicInteger atomicNumYslcdss= new AtomicInteger(1);
        yslcdssList.stream().map(yslcdss -> {
            AnalysisListDto AnalysisListDto=new AnalysisListDto();
            AnalysisListDto.setMonitorType("涌水量");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            AnalysisListDto.setMonitorTime(sdf.format(yslcdss.getMonitorTime()));
            AnalysisListDto.setMonitorValue(yslcdss.getValue());
            QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
            sysDepartQueryWrapper.eq("org_code", yslcdss.getStationMine());
            SysDepart sysDepart = sysDepartMapper.selectOne(sysDepartQueryWrapper);
            AnalysisListDto.setStationName(sysDepart.getDepartName());
            AnalysisListDto.setMonitorStation(yslcdss.getLocation());
            AnalysisListDtoList.add(AnalysisListDto);
            return null;
        }).collect(Collectors.toList());
        return AnalysisListDtoList;
    }
    /**
     * 实时通知所有
     * @return
     */
    List<AnalysisListDto> switchAll(String codestationMine){
        List<AnalysisListDto> AnalysisListDtoList=new ArrayList<>();
        List<AnalysisListDto> list1=switchCgkcdss(codestationMine);
        list1.stream().forEach(dto1->{
            AnalysisListDtoList.add(dto1);
        });
        List<AnalysisListDto> list2=switchJsldss(codestationMine);
        list2.stream().forEach(dto2->{
            AnalysisListDtoList.add(dto2);
        });
        List<AnalysisListDto> list3=switchPslcdss(codestationMine);
        list3.stream().forEach(dto1->{
            AnalysisListDtoList.add(dto1);
        });
        List<AnalysisListDto> list4=switchCscdss(codestationMine);
        list4.stream().forEach(dto1->{
            AnalysisListDtoList.add(dto1);
        });
        List<AnalysisListDto> list5=switchWzcdss(codestationMine);
        list5.stream().forEach(dto1->{
            AnalysisListDtoList.add(dto1);
        });
        List<AnalysisListDto> list6=switchDbcx(codestationMine);
        list6.stream().forEach(dto1->{
            AnalysisListDtoList.add(dto1);
        });
        List<AnalysisListDto> list7=switchDbscdss(codestationMine);
        list7.stream().forEach(dto1->{
            AnalysisListDtoList.add(dto1);
        });
        List<AnalysisListDto> list8=switchYslcdss(codestationMine);
        list8.stream().forEach(dto1->{
            AnalysisListDtoList.add(dto1);
        });
        return AnalysisListDtoList;
    }
}
